<!DOCTYPE html>
<html>
<head>
    <meta charset="utf-8">
    <meta name="viewport" content="initial-scale=1.0, maximum-scale=1.0, user-scalable=no"/>
    <title></title>
    <div>
        <h3>常量</h3>
        <p>手机通讯录(phoneBook): <span id="phoneBook"></span></p>
        <p>SIM卡通讯录(simBook): <span id="simBook"></span></p>
    </div>
    <div>
        <h3>方法</h3>
        <p>通讯录的增删改查</p>
    </div>
    <script type="text/javascript">
                var phoneBook = document.getElementById('phoneBook');
                var simBook = document.getElementById('simBook');

                // 属性
                function plusReady() {
                    phoneBook.innerText = plus.contacts.ADDRESSBOOK_PHONE;
                    simBook.innerText = plus.contacts.ADDRESSBOOK_SIM;

                }
                if (window.plus) {
                    plusReady();
                    
                } else {
                    document.addEventListener("plusready", plusReady, false);
                }
                // 方法
                // 监听plusready事件
                document.addEventListener("plusready", function () {
                    // 扩展API加载完毕，现在可以正常调用扩展API
                    plus.contacts.getAddressBook(plus.contacts.ADDRESSBOOK_PHONE, function (addressbook) {
                        // 可通过addressbook进行通讯录操作
                        console.log(addressbook);
                        // 向通讯录中添加联系人
                        var contact = addressbook.create();
                        contact.name = {givenName: "张三"};
                        contact.phoneNumbers = [{type: "手机", value: "88888888", preferred: true}];
                        contact.save();

                        // 查找通讯录联系人
                        addressbook.find(["李四", "0"], function (contacts) {
                            // 获取联系人通讯录
                            console.log(contacts);
                        }, function () {
                            alert("error");
                        }, {multiple: true});

                        // 删除联系人
                        /*addressbook.find(null, function (contacts) {
                            if (contacts.length > 0) {
                                var dc = contacts[0];
                                dc.remove( function () {
                                    alert( "Remove "+dc.displayName+" success!" );
                                });
                            }
                        }, function ( e ) {
                            alert( "Find contact error: "+ e.message );
                        }, {filter:[{logic:"or",field:"phoneNumbers",value:"88888888"}],multi:false});*/

                    }, function (e) {
                        alert("Get address book failed: " + e.message);
                    });
                }, false);
    </script>
</head>
<body>

</body>
</html>